<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/28 0028
 * Time: 21:08
 */
$ppid = posix_getpid();
//$pppid = posix_getppid();
echo $ppid . PHP_EOL;
//echo $pppid . PHP_EOL;
$a = 1;
for ($i = 0; $i < 1; $i++) {
    $pid = pcntl_fork();
    if ($pid < 0) {
        exit('创建失败');
    } elseif ($pid > 0) {
        //父进程空间 返回子进程ID
        // $a = 2;
        //echo 'a2= ' . $a;
        $status = 0;
        $pid = pcntl_wait($status); //结束的子进程信息，阻塞状态
        echo "子进程ID=" . $pid . PHP_EOL;

    } elseif ($pid == 0) { // 返回0子进程空间
        //子进程创建成功
//        echo '子进程空间';
        echo '==' . $pid . PHP_EOL;
        // $a = 3;
        //echo 'a3= ' . $a;
        sleep(20);
    }

}

